#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
bool flag=false;
int limit;
void dfs(string s,string p,string now,int pos1,int pos2){
         if(flag) return;
         if(now.size()>p.size()) return;
         if(now.length()==s.length()&&now==s)
         {
             flag=true;
             return;
         }
         if(p[pos2]=='*')
         {
            char str=p[pos2-1];
            if(str=='.')
            {
                flag=true;
                return;
            }
            else if(str=='*')
            {
                int cnt=s.length()-pos1;
                char op=now.back();
                string temp="";
                for(int k=1;k<=cnt;k++)
                {
                    temp+=op;
                    if(s.find(temp,pos1)!=string::npos)
                    {
                        dfs(s,p,now+temp,pos1+k-1,pos2+1);
                    }
                    else return;
                }
            }
            else{
                int cnt=s.length()-pos1;
                string temp="";
                for(int k=1;k<=cnt;k++)
                {
                    temp+=s[pos1];
                    if(s.find(temp,pos1)!=string::npos)
                    {
                        dfs(s,p,now+temp,pos1+k,pos2+1);
                    }
                    else return;
                }
            }
         }
         else if(p[pos2]=='.')
         {
             dfs(s,p,now+s[pos1],pos1+1,pos2+1);
         }
         else{
             if(s[pos1]==p[pos2]) dfs(s,p,now+s[pos1],pos1+1,pos2+1);
             else if(s[pos1]!=p[pos2]&&s[pos2+1]=='*') dfs(s,p,now,pos1,pos2+2);
             else return;
         }
}
bool isMatch(string s, string p) {
         limit=s.size()-1;
         string now="";
         dfs(s,p,now,0,0);
         if(flag) return true;
         else return false;
}
int main(void){
    string s,p;cin>>s>>p;
   	cout<<isMatch(s,p)<<endl;
   	return 0;
}
